/*
Rilego - An easy Images 2 E-Book converter.
Copyright (C) 2011  Federico Improta (Kirys)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
package it.kirys.rilego.gui.filtersmanager.nodesmanaging;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.LinkedList;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Federico Improta
 */
public abstract class CompositeLeafEditor<T> extends JPanel implements IVisualLeafEditor<T> {

	private BorderLayout layout;
	private JLabel label;
	LinkedList<ValueChangedEventListener> listeners;
	IEditableTreeLeaf leaf;

	@Override
	public void setLeaf(IEditableTreeLeaf leaf) {
		this.leaf = leaf;
	}

	@Override
	public IEditableTreeLeaf getLeaf() {
		return this.leaf;
	}

	protected void done() {
		for (ValueChangedEventListener li : listeners) {
			li.valueChanged(leaf);
		}
	}

	public JLabel getLabel() {
		return label;
	}//public JLabel getLabel()

	@Override
	public BorderLayout getLayout() {
		return layout;
	}//public BorderLayout getLayout()

	@Override
	public void setLabel(String aLablel) {
		label.setText(aLablel);
	}//public void setLabel(String aLablel)

	public void assignEditor(JComponent editor) {
		label.setLabelFor(editor);
		this.add(editor, BorderLayout.CENTER);
	}//public void assignEditor(JComponent editor)

	public CompositeLeafEditor() {
		layout = new BorderLayout();
		this.setLayout(layout);
		label = new JLabel();
		label.setMinimumSize(new Dimension(100, 20));
		this.add(label, BorderLayout.WEST);
		listeners = new LinkedList<ValueChangedEventListener>();
	}//public CompositeLeafEditor()

	@Override
	public void addListener(ValueChangedEventListener listener) {
		listeners.add(listener);
	}
}
